package com.itheima.web;

import com.github.pagehelper.PageInfo;
import com.itheima.domain.Banner;
import com.itheima.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.management.BadBinaryOpValueExpException;
import java.util.Arrays;

/*@Controller
@ResponseBody*/
@RestController
@RequestMapping("/banner")
public class BannerController {
    @Autowired
    private BannerService bannerService;

    /*分页查询列表*/
    @GetMapping("/findByPage")
    public PageInfo<Banner> findByPage(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                        @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize,
                                       String keyword) {
        PageInfo<Banner> pageInfo = bannerService.findByPage(pageNum, pageSize,keyword );

        /*g根据关键字查询*/

        return pageInfo;
    }

/*添加banner*/
    @PostMapping("/save")
    public String  save(@RequestBody Banner banner) {
        bannerService.save(banner);
        return "ok";

    }
/*根据id查询*/
    @GetMapping("/findById")
    public Banner findById(Integer id) {
        Banner banner = bannerService.findById(id);
        return  banner;
    }

    //    根据id删除
    @DeleteMapping("/delete")
    public String delete(Integer id) {
        bannerService.deleteById(id);
        return "ok";
    }

    // //根据id数组进行删除
    @DeleteMapping("deleteByIds")
    public  String deleteByIds(Integer[] ids) {
        bannerService.deleteByIds(ids);
        return "ok";
    }

}
